home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / C-H / CHexDmpDA.cpt / Hex Dump DA / file.HexDumpDA.c < prev    next >
C/C++ Source or Header  |  1988-06-15  |  2KB  |  107 lines

  1. #include <WindowMgr.h>
  2. #include <StdFilePkg.h>
  3. #include <FileMgr.h>
  4.  
  5. #include "HexDump.h"
  6.  
  7. extern long linesInFile;
  8. extern long firstByte;
  9. extern WindowPtr wp;
  10. extern Cursor wait;
  11.  
  12. extern     SFReply reply;
  13.  
  14. int        fileRef = 0;        /*  the refnum of the file we're showing */
  15. long    fileSize;            /*    and the file's size (in bytes)         */
  16.  
  17. #define     LOCBUFSIZE    512L
  18.  
  19. doDumpTo()
  20. {
  21.     long     count, i;
  22.     char    cr = 0x0D;
  23.     int     outRef;
  24.     SFReply reply;
  25.     char    buffer[LOCBUFSIZE];
  26.     Str255    dumpFileName;
  27.     long    first;
  28.     static    Point    where = { 100, 104 };
  29.     char    display[128];
  30.     
  31.     GetWTitle( wp, dumpFileName );
  32.     pstrcat( dumpFileName, "\p dump");
  33.     SFPutFile(where, "\pDump to file:", dumpFileName, 0L, &reply);
  34.     if (!reply.good) return(0);
  35.     doUpdate();
  36.     FSDelete(reply.fName, reply.vRefNum);
  37.     Create( reply.fName, reply.vRefNum, '????', 'TEXT' );
  38.     if ( FSOpen( reply.fName, reply.vRefNum, &outRef ) == noErr) {
  39.         SetCursor(&wait);
  40.         SetFPos( fileRef, fsFromStart, first = 0L );
  41.         count = LOCBUFSIZE;
  42.         FSRead( fileRef, &count, buffer );
  43.         for (i=0; i<=linesInFile*16L; i+=16) {
  44.             if (i-first >= LOCBUFSIZE) {
  45.                 first += count = LOCBUFSIZE;
  46.                 FSRead( fileRef, &count, buffer );
  47.             }
  48.             Fill_Line( i, &buffer[i-first], display );
  49.             count = display[0];
  50.             display[++count]=cr;
  51.             FSWrite( outRef, &count, &display[1] );
  52.         }
  53.         FSClose( outRef );
  54.         InitCursor();
  55.     }
  56.     else SysBeep(3);
  57. }
  58.  
  59. FSOpen_RF( fileName, vRefNum, refNum )
  60. char     *fileName;
  61. int     vRefNum;
  62. int        *refNum;
  63. {
  64.     IOParam pb;
  65.     
  66.     pb.ioCompletion = 0L;
  67.     pb.ioNamePtr = (StringPtr) fileName;
  68.     pb.ioVRefNum = vRefNum;
  69.     pb.ioMisc = 0L;
  70.     pb.ioVersNum = 0;
  71.     pb.ioPermssn = fsRdPerm;
  72.     PBOpenRF( &pb, 0 );
  73.     *refNum = pb.ioRefNum;
  74.     return pb.ioResult;
  75. }
  76.  
  77. New_Open_File(newFileRef)
  78. int newFileRef;
  79. {
  80.     Close_File( fileRef );
  81.     fileRef = newFileRef;
  82.     GetEOF( fileRef, &fileSize );
  83.     New_File_Window( fileSize, reply.fName );
  84. }
  85.  
  86. Open_Fork(fork, ref )
  87. enum fork fork;
  88. int     *ref;
  89. {
  90.     *ref = 0;
  91.     if (fork==data) {
  92.         if (No_Error(FSOpen(reply.fName, reply.vRefNum, ref)))
  93.             return 1;
  94.         }
  95.     else if (No_Error(FSOpen_RF(reply.fName, reply.vRefNum, ref)))
  96.             return 1;
  97.     if (*ref)
  98.         FSClose(*ref);
  99.     return 0;
  100. }
  101.  
  102. Close_File(refNum)
  103. int refNum;
  104. {
  105.     if (refNum) FSClose(refNum);
  106. }
  107.